<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>首页 - 驴妈妈流立方</title>
		<meta name="description" content="overview &amp; stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		<script src="${rc.contextPath}/assets/js/jquery.2.1.1.min.js"></script>
		<script src="${rc.contextPath}/assets/js/bootstrap.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery-ui.custom.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="${rc.contextPath}/assets/js/bootbox.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery.gritter.min.js"></script>
		<script src="${rc.contextPath}/assets/js/spin.min.js"></script>
		<!-- ace scripts -->
		<script src="${rc.contextPath}/assets/js/ace-elements.min.js"></script>
		<script src="${rc.contextPath}/assets/js/ace.min.js"></script>
		<!-- validator scripts -->
		<script src="${rc.contextPath}/assets/js/bootstrapValidator.min.js"></script>
		<!-- user scripts -->
		<script src="${rc.contextPath}/assets/js/user/base.js"></script>
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/font-awesome/4.2.0/css/font-awesome.min.css" />
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/jquery-ui.custom.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/jquery.gritter.min.css" />
		<!-- text fonts -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/fonts/fonts.googleapis.com.css" />
		<!-- BootstrapValidator -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/bootstrapValidator.min.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
		<!-- ace settings handler -->
		<script src="${rc.contextPath}/assets/js/ace-extra.min.js"></script>
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/bsie-paginator.css" />

	</head>

	<body class="no-skin" style="background-color: #FFF;">
		<div class="page-content">
		<div class="tab-content">
			<div class="row">
				<div class="col-xs-12">
					<div class="widget-box">
						<div class="widget-header widget-header-small">
							<h5 class="widget-title lighter">筛选条件</h5>
						</div>
						<div class="widget-body" style="background-color: #EFF3F8;">
							<div class="widget-main">
								<form class="form-inline" id="searchForm" method="post" action="${rc.contextPath}/performanceStatistics/interfacePerformanceMonitoring">
									<input id="chooseTimeVO" type="hidden" name="chooseTimeVO" value="${monitorVO.chooseTimeVO}">
									<input id="chooseTimeTableVO" type="hidden" name="chooseTimeTableVO" value="${monitorVO.chooseTimeTableVO}">
									<input id="pageSizeForm" type="hidden" name="pageSize" value="${monitorVO.pageSize}">
									<div class="form-group">
										<label for="exampleInputName2">选择时段</label> 
										<input type="text" id="config-demo" name="config-demo" class="form-control time" value="${monitorVO.chooseTimeVO}">
											<button id="app_search" type="button"  onclick="replaceDate('1');" class="btn btn-white btn-sm">
												<span class="ace-icon icon-on-right bigger-110"></span>
												过去一周
											</button>
											<button id="app_search" type="button"  onclick="replaceDate('2');" class="btn btn-white btn-sm">
												<span class="ace-icon icon-on-right bigger-110"></span>
												过去两周
											</button>
									</div>
									<div class="form-group">
										<label for="exampleInputName2">接口名</label>
										<input type="text" id="apiName" class="form-control" name="apiName" onchange="searchApiVersion();" value="${monitorVO.apiName}">
									</div>
									<div class="form-group">
										<label for="exampleInputName2">接口版本</label> 
										<select data-placeholder="" class="chosen-select" tabindex="2" name="apiVersion" id="apiVersion" >
											<option value="">全部</option>
											<#list apiVersions as apiVersionObj>
												<option value="${apiVersionObj}" <#if monitorVO.apiVersion == apiVersionObj>selected</#if>>${apiVersionObj}</option>
											</#list>
										</select>
									</div>
									<div class="form-group">
									  	<button id="search" type="button" onclick="searchClick();" class="btn btn-pink btn-sm">
											<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
											Search
										</button>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			
			<div class="row">
				<div class="col-xs-12">
					<div class="widget-box">
						<div class="widget-header widget-header-small">
							<div class="row">
								<div class="col-xs-12">
									<!-- <h5 class="widget-title lighter">业务性能服务</h5> -->
									<div id="businessServicePerformance" style="width: 100%; height: 350px; margin: 0 auto;"></div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<div style="width: 100%; margin: 0 auto;">
									<table id="simple-table" class="table table-striped table-bordered table-hover" style="margin-bottom: 0px;border-bottom: 0px;">
										<thead>
											<tr>
												<th>序号</th>
												<th>接口名</th>
												<th>接口版本</th>
												<th>app类型</th>
												<th>运营商</th>
												<th>网络制式</th>
												<th>平均接口内部耗时(ms)</th>
												<th>平均首包时间(ms)</th>
												<th>平均传输时间(ms)</th>
												<th>调用量</th>
											</tr>
										</thead>
										<tbody id="tableData">
											<#if monitorApiList?? && monitorApiList?size&gt;0>
												<#list monitorApiList as monitorApi>
													<tr class="">
														<td>${monitorApi_index + 1}</td>
														<td>${monitorApi.apiName}</td>
														<td>${monitorApi.apiVersion!}</td>
														<td>${monitorApi.appType}</td>
														<td>${monitorApi.operators}</td>
														<td>${monitorApi.networkType}</td>
														<td>${monitorApi.avgApiTime}</td>
														<td>${monitorApi.avgFirstPackageTime!}</td>
														<td>${monitorApi.avgTransferTime}</td>
														<td>${monitorApi.amount}</td>
													</tr>
												</#list>
											<#else>
												<tr>
													<td colspan="12">
														<div class="alert alert-danger" style="margin-bottom: 0px;" role="alert">没有记录!</div>
													</td>
												</tr>
											</#if>
										</tbody>
									</table>
									<#include "paginatorUpgrade.html">
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			
		</div>

		<script src="${rc.contextPath}/assets/js/moment.min.js"></script>
		<script src="${rc.contextPath}/assets/js/bootstrap-datetimepicker.min.js"></script>
		
		<!-- <link rel="stylesheet" href="${rc.contextPath}/stylesheets/bootstrap.min.css"> -->
		<!-- <link rel="stylesheet" href="${rc.contextPath}/stylesheets/bootstrap-theme.min.css"> -->
		<link rel="stylesheet" href="${rc.contextPath}/stylesheets/daterangepicker.css">
		<script type="text/javascript" src="${rc.contextPath}/javascripts/jquery.2.1.1.min.js"></script>
	   	<script type="text/javascript" src="${rc.contextPath}/javascripts/bootstrap.min.js"></script>
	   	<script type="text/javascript" src="${rc.contextPath}/javascripts/moment.js"></script>
	   	<script type="text/javascript" src="${rc.contextPath}/javascripts/daterangepicker.js"></script>
	   	
	   	<script type="text/javascript" src="${rc.contextPath}/javascripts/echarts.js"></script>
	   	<script type="text/javascript" src="${rc.contextPath}/javascripts/china.js"></script>
	   	<script src="${rc.contextPath}/assets/js/jquery.gritter.min.js"></script>
		<script type="text/javascript">
			function replaceDate(obj){
	    		if(obj == '1'){
	    			startDate = new Date(new Date().getTime()-7*1000*60*60*24);
		    		endDate = new Date(new Date().getTime()-1*1000*60*60*24);
	    		}else if(obj == '2'){
	    			startDate = new Date(new Date().getTime()-14*1000*60*60*24);
		    		endDate = new Date(new Date().getTime()-1*1000*60*60*24);
	    		}
			 	var dateStr = dateFormat(startDate) + " - " + dateFormat(endDate);
			    $("#chooseTimeVO").val(dateStr);
			    $(".time").val(dateStr);
	    	}
		
			function dateFormat(date){
	    		var month = date.getMonth() + 1;
    		    var strDate = date.getDate();
    		    if (month >= 1 && month <= 9) {
    		        month = "0" + month;
    		    }
    		    if (strDate >= 0 && strDate <= 9) {
    		        strDate = "0" + strDate;
    		    }
    		    var currentdate = month + "/" + strDate + "/" + date.getFullYear();
    		    return currentdate;
	    	}

			function searchClick() {
				var chooseTime = $("#config-demo").val();
				var pageSize = $("#pageSize").val();
				$('#chooseTimeVO').val(chooseTime);
				$('#chooseTimeTableVO').val(null);
				$('#pageSizeForm').val(pageSize);
				$("#searchForm").submit();
			}
			
			function searchApiVersion(){
				var apiName = $("#apiName").val();
				$.ajax({
					url : "${rc.contextPath}/performanceStatistics/actionApiVersion",
					type:'post',
					data : {
						"apiName" : apiName
					},
					dataType : "json",
					success : function(data) {
						if(data!=null){
							var apiVersions = data.apiVersions;
							var html = '<option value="">全部</option>';
							for(var i=0;i<apiVersions.length;i++){
								var apiVersion = apiVersions[i];
								html += '<option value="'+apiVersion+'">'+apiVersion+'</option>';
							}
							$("#apiVersion").html(html);
							$('#apiVersion').chosen("destroy").chosen();
						}
					}
				});
			}
		
			jQuery(function($) {
				$('.time').daterangepicker(
						{
							startDate: new Date(new Date().getTime()-1*1000*60*60*24),
						    endDate: new Date(new Date().getTime()-1*1000*60*60*24),
							showDropdowns : true,
							showWeekNumbers : false,
							timePicker : false,
							timePicker12Hour : false,
							ranges : {
								'昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
				            	'过去7天': [moment().subtract(7, 'days'), moment().subtract(1, 'days')],  
				                '过去31天': [moment().subtract(31, 'days'), moment().subtract(1, 'days')]
							},
							opens : 'right',
							buttonClasses : [ 'btn btn-default' ],
							applyClass : 'btn-small btn-pink blue',
							cancelClass : 'btn-small',
							format : 'yyyy-MM-dd',
							separator : ' to ',
							locale : {
								applyLabel : '确定',
								cancelLabel : '取消',
								fromLabel : '起始时间',
								toLabel : '结束时间',
								customRangeLabel : '自定义',
								daysOfWeek : [ '日', '一', '二', '三', '四', '五',
										'六' ],
								monthNames : [ '一月', '二月', '三月', '四月', '五月',
										'六月', '七月', '八月', '九月', '十月', '十一月',
										'十二月' ],
								firstDay : 1
							}
						},
						function(start, end, label) {//格式化日期显示框  

							$('.time').html(
									start.format('yyyy-MM-dd') + ' - '
											+ end.format('yyyy-MM-dd'));
						});
				
				var chooseTimeVO = "${monitorVO.chooseTimeVO}";
				if(chooseTimeVO != ""){
					$('#config-demo').val(chooseTimeVO);
				}

				/* 数值每3位，逗号隔开 */
				function formatNum(strNum) {
					if (strNum.length <= 3) {
						return strNum;
					}
					if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(strNum)) {
						return strNum;
					}
					var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
					var re = new RegExp();
					re.compile("(\\d)(\\d{3})(,|$)");
					while (re.test(b)) {
						b = b.replace(re, "$1,$2$3");
					}
					return a + "" + b + "" + c;
				}
				
				
				option1 = {
				    //color: ['#3398DB'],
				    title : {
						text : '业务服务性能图',
						/* left : 'center',
						top : '2%' */
					}, 
				    tooltip : {
				        trigger: 'axis',
				        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
				            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
				        },
				        //formatter :'日期 : {b} <br/>接口内部耗时 : {c}ms'
				    },
				    legend: {
				        data:['平均传输时间','平均首包时间','平均接口内部耗时']
				    },
				    toolbox: {
	   			        show: true,
	   			        feature: {
	   			           /* 
	   			                //区域放大，缩小
	   			                dataZoom: {
	   			                yAxisIndex: 'none'
	   			            }, */  
	   			            dataView: {readOnly: true},
	   			            magicType: {type: ['line', 'bar']},
	   			            restore: {},
	   			            saveAsImage: {}
	   			        }
	   			    },
	   			 	dataZoom: [
		   			         {
		   			             show: true,
		   			             start: 0,
		   			             end: 100,
		   			         },
		   			         
		   			     ],
				    grid: {
				        left: '3%',
				        right: '10%',
				        bottom: '12%',
				        containLabel: true
				    },
				    xAxis : [
				        {
				            type : 'category',
				            name : '日期',
				            data : [],
				            axisTick: {
				                alignWithLabel: true
				            }
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value',
				            name : '接口耗时/ms'
				        }
				    ],
				    series : [
						{
						    name:'平均传输时间',
						    type:'line',
						    barWidth: '60%',
						    stack: '总量',
						    areaStyle: {normal: {}},
						    label: {
						        normal: {
						            show: true,
						            position: 'top',
						            formatter: function(p){
						        		return formatNum(p.value);
						        	}
						        }
						    },
						    data:[]
						},
				        {
				            name:'平均首包时间',
				            type:'line',
				            barWidth: '60%',
				            stack: '总量',
				            areaStyle: {normal: {}},
				            label: {
				                normal: {
				                    show: true,
				                    position: 'top',
				                    formatter: function(p){
			                    		return formatNum(p.value);
			                    	}
				                }
				            },
				            data:[]
				        },		
				        {
				            name:'平均接口内部耗时',
				            type:'line',
				            barWidth: '60%',
				            stack: '总量',
				            areaStyle: {normal: {}},
				            label: {
				                normal: {
				                    show: true,
				                    position: 'top',
				                    formatter: function(p){
			                    		return formatNum(p.value);
			                    	}
				                }
				            },
				            data:[]
				        }
				    ]
				};
				
				var monitorApiJsonXAxis = eval('${monitorApiJsonXAxis!}');
				var apiTimeJsonData = eval('${apiTimeJsonData!}');
				var firstPackageTimeJsonData = eval('${firstPackageTimeJsonData!}');
				var transferTimeJsonData = eval('${transferTimeJsonData!}');
				
				option1.xAxis[0].data = monitorApiJsonXAxis;
				option1.series[2].data = apiTimeJsonData;
				option1.series[1].data = firstPackageTimeJsonData;
				option1.series[0].data = transferTimeJsonData;
				
				myChart1 = echarts.init(document.getElementById('businessServicePerformance'));
			 	myChart1.setOption(option1,true);
			 	
			 	myChart1.on('click', function (params) {
			 		var chooseTimeVO = $("#chooseTimeVO").val();
			 		var apiName = $("#apiName").val();
			 		var apiVersion = $("#apiVersion").val();
			 		var pageSize = $("#pageSizeForm").val();
			 		$.ajax({
						url : "${rc.contextPath}/performanceStatistics/ajaxDetailedTable",
						type:'post',
						data : {
							"chooseTimeVO" : chooseTimeVO,
							"chooseTimeTableVO" : params.name,
							"apiName" : apiName,
							"apiVersion" : apiVersion,
							"page" : 1,
							"pageSize" : pageSize
						},
						dataType : "json",
						success : function(data) {
							if(data!=null){
								var page = data.page;
								var monitorApiList = data.monitorApiList;
								var monitorVO = data.monitorVO;
								var chooseTimeTableVO = data.monitorVO.chooseTimeTableVO;
								$("#chooseTimeTableVO").val(chooseTimeTableVO);
								$(".ui-pg-input").val(page.pageNum);
								$("#sp_1_grid-pager").html(page.pages);
								var val = 'Page Size:<input id="pageSize" class="ui-pg-input" type="text" size="2" maxlength="7" value="'+page.pageSize+'"  role="textbox">&nbsp;'
									+ 'View '+page.startRow+' - '+page.endRow+' of '+page.total;
								$(".ui-paging-info").html(val);
								$("#first_grid-pager").attr("onclick","showPage("+page.firstPage+",this)");
								$("#prev_grid-pager").attr("onclick","showPage("+page.prePage+",this)");
								$("#next_grid-pager").attr("onclick","showPage("+page.nextPage+",this)");
								$("#last_grid-pager").attr("onclick","showPage("+page.lastPage+",this)");
								if(monitorApiList != null){
									var html = '';
									for(var i=0;i<monitorApiList.length;i++){
										var index = i+1;
										var apiName = monitorApiList[i].apiName;
										var apiVersion = monitorApiList[i].apiVersion;
										var appType = monitorApiList[i].appType;
										var operators = monitorApiList[i].operators;
										var networkType = monitorApiList[i].networkType;
										var avgApiTime = monitorApiList[i].avgApiTime;
										var avgFirstPackageTime = monitorApiList[i].avgFirstPackageTime;
										var avgTransferTime = monitorApiList[i].avgTransferTime;
										var amount = monitorApiList[i].amount;
										html += '<tr class=""><td>'+index+'</td><td>'+apiName+'</td><td>'+apiVersion+
												'</td><td>'+appType+'</td><td>'+operators+
												'</td><td>'+networkType+'</td><td>'+avgApiTime+
												'</td><td>'+avgFirstPackageTime+'</td><td>'+avgTransferTime+'</td><td>'+
												amount+'</td></tr>';
									} 
									$("#tableData").html(html);
								}else{
									var html = '<tr><td colspan="12"><div class="alert alert-danger" style="margin-bottom: 0px;" role="alert">没有记录!</div></td></tr>';
									$("#tableData").html(html);
								}
								
							}
						}
					});
			 	});
			 	
		  	  	window.onresize = function(){
	  	  	  		myChart1.resize();
		  	  	} 

			})
			
			
		</script>


		<link rel="stylesheet" href="${rc.contextPath}/assets/css/bootstrap.css" /> 
		<script src="${rc.contextPath}/assets/js/chosen.jquery.js"></script>
		
		<script>
			 $(function() {
		        $('.chosen-select').chosen();
		       	$('.chosen-select-deselect').chosen({ allow_single_deselect: true });
		     }); 
	      	
			 function statistics(){
				$('#statistics').show();
				$('.chosen-select').chosen("destroy").chosen();
		       	$('.chosen-select-deselect').chosen({ allow_single_deselect: true });
			 }
	    </script>
	    
	</body>
</html>